<?php

//decode by 012wz.com QQ:800083075
global $_W, $_GPC;
$operation = empty($_GPC['op']) ? 'display' : $_GPC['op'];
if ($operation == 'display') {
	ca('creditshop.log.view' . $type);
	$pindex = max(1, intval($_GPC['page']));
	$psize = 20;
        if (!empty($_POST['realname'])) {
                $condition="";
                $_POST['realname'] = trim($_POST['realname']);
                $condition .= ' and ( m.weixin like :realname or m.realname like :realname or m.mobile like :realname or m.nickname like :realname)';
                $params[':realname'] = "%{$_POST['realname']}%";
                $list = pdo_fetchAll("SELECT r.*, FROM_UNIXTIME(r.createtime,'%Y-%m-%d') as cdate,FROM_UNIXTIME(r.createtime,'%T') as ctime,r.createtime,m.avatar,m.realname,m.mobile,m.weixin,m.company,m.gender,m.province,m.city,m.area,m.nickname  FROM " . tablename('mc_golds_record') . " r left  join " . tablename('ewei_shop_member') . " m on r.uid=m.uid and r.uniacid=m.uniacid" . " WHERE r.uid =m.uid  AND r.remark='金币充值' AND r.uniacid=" . $_W['uniacid'] . " $condition order by r.id desc",$params);
                foreach($list as $key => $value){
                    $list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
                }
        }else{
                $list = pdo_fetchAll("SELECT r.*, FROM_UNIXTIME(r.createtime,'%Y-%m-%d') as cdate,FROM_UNIXTIME(r.createtime,'%T') as ctime,r.createtime,m.avatar,m.realname,m.mobile,m.weixin,m.company,m.gender,m.province,m.city,m.area,m.nickname  FROM " . tablename('mc_golds_record') . " r left  join " . tablename('ewei_shop_member') . " m on r.uid=m.uid and r.uniacid=m.uniacid" . " WHERE r.uid =m.uid  AND r.remark='金币充值' AND r.uniacid=" . $_W['uniacid'] . " order by r.id desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
                foreach($list as $key => $value){
                    $list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
                }
                $total = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('mc_golds_record') . " WHERE remark='金币充值' AND uniacid = '{$_W['uniacid']}' ORDER BY id DESC");
                $pager = pagination($total, $pindex, $psize);
        }
        if ($_GPC['export'] == 1) {
		foreach ($list as $key => $value){
                        if($value['gender']==1){
                        $list[$key]["gender"]="男";
                        }else{
                        $list[$key]["gender"]="女";  
                        }
                        $list[$key]["address"]=$value['province'].' '.$value['city'].''.$value['area']; 
		}
		$columns = array(
                    array('title' => 'ID', 'field' => 'id', 'width' => 12),
                    array('title' => '昵称', 'field' => 'nickname', 'width' => 12), 
                    array('title' => '微信号', 'field' => 'weixin', 'width' => 12),
                    array('title' => "充值时间", 'field' => 'createtime', 'width' => 24),
                    array('title' => '姓名', 'field' => 'realname', 'width' => 12),
                    array('title' => '手机号码', 'field' => 'mobile', 'width' => 12),
                    array('title' => '充值金额', 'field' => 'num', 'width' => 12),
                    array('title' => '性别', 'field' => 'gender', 'width' => 12),
                    array('title' => '所在城市', 'field' => 'address', 'width' => 12),
                    array('title' => '内容', 'field' => 'remark', 'width' => 12)
               );
                m('excel')->export($list, array("title" => "金币充值记录导出" . date('Y-m-d-H-i', time()), "columns" => $columns));
	}
}
load()->func('tpl');
include $this->template('recharge_log');